package com.test.controller;


import com.test.service.StuOperatService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class ViewController {

    @RequestMapping("/login")
    public String loginIndex(HttpSession session){
        String acount = null;
        if(session.getAttribute("stu_u_acount")!=null&&!"".equals(session.getAttribute("stu_u_acount"))){
            acount= session.getAttribute("stu_u_acount").toString();
        }else{
            acount= StuOperatService.stuAcount;
            session.setAttribute("stu_u_acount",acount);

        }
        if(acount!=null&&!"".equals(acount)){
            return  "no_login";
        }else{
            return "login";
        }

    }


    @RequestMapping("/scanlogin")
    public void no_login(HttpSession session){
        String acount= StuOperatService.stuAcount;
        session.setAttribute("stu_u_acount",acount);
        String url = "http://127.0.0.1:8099/login";
        int num=0;
        try {
            if(num<1){
                num++;
                Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);//使用默认浏览器打开url
            }else{

            }
        }catch (Exception e){

        }

    }

    @RequestMapping("/login_qrcode")
    public String login_qrcode(){
        return  "loginQrCode";
    }

    @RequestMapping("/tealogin")
    public String tealogin(HttpSession session){
        String acount = null;
        if(session.getAttribute("tea_u_acount")!=null&&!"".equals(session.getAttribute("stu_u_acount"))){
            acount= session.getAttribute("tea_u_acount").toString();
        }
        if(acount!=null&&!"".equals(acount)){
            return  "no_tealogin";
        }else{
            return  "tealogin";
        }

    }

    @RequestMapping("/complogin")
    public String complogin(HttpSession session){

        String acount = null;
        if(session.getAttribute("comp_acount")!=null&&!"".equals(session.getAttribute("stu_u_acount"))){
            acount= session.getAttribute("comp_acount").toString();
        }
        if(acount!=null&&!"".equals(acount)){
            return  "no_complogin";
        }else{
            return  "complogin";
        }

    }

    @RequestMapping("/phonelogin")
    public String phonelogin(){
        return  "phonelogin";
    }

    @RequestMapping("/index")
    public String index(HttpSession session){

        String acount = null;
        if(session.getAttribute("stu_u_acount")!=null&&!"".equals(session.getAttribute("stu_u_acount"))){
             acount= session.getAttribute("stu_u_acount").toString();
        }

        if(acount!=null&&!"".equals(acount)){
            return  "index";
        }else{
            return "login";
        }
    }

    @RequestMapping("/publicIndex")
    public String publicIndex(HttpSession session){

        String acount = null;
        if(session.getAttribute("stu_u_acount")!=null&&!"".equals(session.getAttribute("stu_u_acount"))){
            acount= session.getAttribute("stu_u_acount").toString();
        }

        if(acount!=null&&!"".equals(acount)){
            return  "publicIndex";
        }else{
            return "login";
        }
    }




    @RequestMapping("/phoneindex")
    public String phoneindex(HttpSession session){

        String acount = null;
        if(session.getAttribute("stu_u_acount")!=null&&!"".equals(session.getAttribute("stu_u_acount"))){
            acount= session.getAttribute("stu_u_acount").toString();
        }
        if(acount!=null&&!"".equals(acount)){
            return  "phoneindex";
        }else{
            return "login";
        }
    }


    @RequestMapping("/stutimetable")
    public String stutimetable(HttpSession session){

        String acount = null;
        if(session.getAttribute("stu_u_acount")!=null&&!"".equals(session.getAttribute("stu_u_acount"))){
            acount= session.getAttribute("stu_u_acount").toString();
        }
        if(acount!=null&&!"".equals(acount)){
            return  "stutimetable";
        }else{
            return "login";
        }
    }


    @RequestMapping("/teacherindex")
    public String teacherindex(HttpSession session){

        String acount = null;
        if(session.getAttribute("tea_u_acount")!=null&&!"".equals(session.getAttribute("tea_u_acount"))){
            acount= session.getAttribute("tea_u_acount").toString();
        }
        if(acount!=null&&!"".equals(acount)){
            return  "teacherindex";
        }else{
            return "tealogin";
        }
    }

    @RequestMapping("/teacher")
    public String teacher(HttpSession session){

        String acount = null;
        if(session.getAttribute("tea_u_acount")!=null&&!"".equals(session.getAttribute("tea_u_acount"))){
            acount= session.getAttribute("tea_u_acount").toString();
        }
        if(acount!=null&&!"".equals(acount)){
            return  "teacher";
        }else{
            return "tealogin";
        }
    }

    @RequestMapping("/employmentdistribution")
    public String employmentdistribution(HttpSession session){

        String acount = null;
        if(session.getAttribute("tea_u_acount")!=null&&!"".equals(session.getAttribute("tea_u_acount"))){
            acount= session.getAttribute("tea_u_acount").toString();
        }
        if(acount!=null&&!"".equals(acount)){
            return  "employmentdistribution";
        }else{
            return "tealogin";
        }
    }



    @RequestMapping("/companyindex")
    public String companyindex(HttpSession session){

        String acount = null;
        if(session.getAttribute("comp_acount")!=null&&!"".equals(session.getAttribute("comp_acount"))){
            acount= session.getAttribute("comp_acount").toString();
        }
        if(acount!=null&&!"".equals(acount)){
            return  "companyindex";
        }else{
            return "complogin";
        }
    }

    @RequestMapping("/stushow")
    public String stushow(HttpSession session){

        String acount = null;
        if(session.getAttribute("comp_acount")!=null&&!"".equals(session.getAttribute("comp_acount"))){
            acount= session.getAttribute("comp_acount").toString();
        }
        if(acount!=null&&!"".equals(acount)){
            return  "stushow";
        }else{
            return "complogin";
        }
    }




    @RequestMapping("/compattentstu")
    public String compattentstu(HttpSession session){

        String acount = null;
        if(session.getAttribute("comp_acount")!=null&&!"".equals(session.getAttribute("comp_acount"))){
            acount= session.getAttribute("comp_acount").toString();
        }
        if(acount!=null&&!"".equals(acount)){
            return  "compattentstu";
        }else{
            return "complogin";
        }
    }

    @RequestMapping("/mycompattentstu")
    public String mycompattentstu(HttpSession session){

        String acount = null;
        if(session.getAttribute("comp_acount")!=null&&!"".equals(session.getAttribute("comp_acount"))){
            acount= session.getAttribute("comp_acount").toString();
        }
        if(acount!=null&&!"".equals(acount)){
            return  "mycompattentstu";
        }else{
            return "complogin";
        }
    }



    @RequestMapping("/infostu")
    public String infostu(HttpSession session){

        String acount = null;
        if(session.getAttribute("comp_acount")!=null&&!"".equals(session.getAttribute("comp_acount"))){
            acount= session.getAttribute("comp_acount").toString();
        }
        if(acount!=null&&!"".equals(acount)){
            return  "infostu";
        }else{
            return "complogin";
        }
    }




    @RequestMapping("/managerindex")
    public String managerindex(HttpSession session){

        String acount = null;
        if(session.getAttribute("mana_u_acount")!=null&&!"".equals(session.getAttribute("mana_u_acount"))){
            acount= session.getAttribute("mana_u_acount").toString();
        }
        if(acount!=null&&!"".equals(acount)){
            return  "managerindex";
        }else{
            return "404";
        }
    }

    @RequestMapping("/resumeInfo")
    public String resumeInfo(HttpSession session){
        String acount = null;
        if(session.getAttribute("stu_u_acount")!=null&&!"".equals(session.getAttribute("stu_u_acount"))){
            acount= session.getAttribute("stu_u_acount").toString();
        }
        if(acount!=null&&!"".equals(acount)){
            return  "resumeInfo";
        }else{
            return "login";
        }
    }



    @RequestMapping("/sut_stroke")
    public String sut_stroke(HttpSession session){
        String acount = null;
        if(session.getAttribute("stu_u_acount")!=null&&!"".equals(session.getAttribute("stu_u_acount"))){
            acount= session.getAttribute("stu_u_acount").toString();
        }
        if(acount!=null&&!"".equals(acount)){
            return "sut_stroke";
        }else{
            return "login";
        }
    }

    @RequestMapping("/compshow")
    public String compshow(HttpSession session){
        String acount = null;
        if(session.getAttribute("stu_u_acount")!=null&&!"".equals(session.getAttribute("stu_u_acount"))){
            acount= session.getAttribute("stu_u_acount").toString();
        }
        if(acount!=null&&!"".equals(acount)){
            return "compshow";
        }else{
            return "404";
        }
    }


    @RequestMapping("/stuOnline")
    public String stuOnline(HttpSession session){
        String acount = null;
        if(session.getAttribute("stu_u_acount")!=null&&!"".equals(session.getAttribute("stu_u_acount"))){
            acount= session.getAttribute("stu_u_acount").toString();
        }
        if(acount!=null&&!"".equals(acount)){
            return "stuOnline";
        }else{
            return "login";
        }
    }
    @RequestMapping("/showCompInfoIndex")
    public String showCompInfoIndex(HttpSession session){
        String acount = null;
        if(session.getAttribute("stu_u_acount")!=null&&!"".equals(session.getAttribute("stu_u_acount"))){
            acount= session.getAttribute("stu_u_acount").toString();
        }
        if(acount!=null&&!"".equals(acount)){
            return "showCompInfoIndex";
        }else{
            return "login";
        }
    }





    @RequestMapping("/attentcompshow")
    public String attentcompshow(HttpSession session){
        String acount = null;
        if(session.getAttribute("stu_u_acount")!=null&&!"".equals(session.getAttribute("stu_u_acount"))){
            acount= session.getAttribute("stu_u_acount").toString();
        }
        if(acount!=null&&!"".equals(acount)){
            return "attentcompshow";
        }else{
            return "login";
        }
    }





    @RequestMapping("/500")
    public String loginfail(){
        return  "500";
    }

    @RequestMapping("/404")
    public String htmlfail(){
        return  "404";
    }

    @RequestMapping("/registration")
    public String registration(){
        return  "registration";
    }

    @RequestMapping("/portal")
    public String portal(){
        return  "portal";
    }

    @RequestMapping("/policiesAndRegulations")
    public String policiesAndRegulations(){
        return  "policiesAndRegulations";
    }

}
